package com.djsearch.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.djsearch.R;
import com.djsearch.controller.JSONResp;
import com.djsearch.widget.DragableCircle;
import com.djsearch.widget.DragableSpace;
import com.djsearch.widget.DragableSpace.OnFlipListener;

/**
 * 欢迎界面
 * 
 * @author yinxing
 * 
 */
public class WelcomeActivity extends BaseActivity {
	DragableSpace dragableSpace;
	DragableCircle circle;
	View welcome1;
	View welcome2;
	View welcome3;
	View welcome4;
	View welcome5;
	RelativeLayout layout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

		dragableSpace = new DragableSpace(this);
		OnFlipListener onFilpListener = new OnFlipListener() {
			@Override
			public void OnFlipEnd(final int ScreenIndex) {
				circle.SetCurrentScreen(ScreenIndex);
//				if(ScreenIndex==4){
//					/**
//					 * 点击跳转到主页
//					 */
//					welcome5.setOnClickListener(new OnClickListener() {
//						@Override
//						public void onClick(View v) {
//							// TODO Auto-generated method stub
//							startActivity(WelcomeActivity.this, MainActivity.class, 0);
//							writeKeyToFile(1);
//						}
//					});
//				}
				if (ScreenIndex == 4) {
					startActivity(WelcomeActivity.this, MainActivity.class, 0);
					writeKeyToFile(1);
					WelcomeActivity.this.finish();
				}
				
			}

			@Override
			public void OnFlipMove(int left, int top) {

				
			}
		};
		dragableSpace.SetOnFlipListener(onFilpListener);

		final LayoutInflater inflater = LayoutInflater.from(this);
		welcome1 = inflater.inflate(R.layout.welcome_1, null);
		welcome2 = inflater.inflate(R.layout.welcome_2, null);
		welcome3 = inflater.inflate(R.layout.welcome_3, null);
		welcome4 = inflater.inflate(R.layout.welcome_4, null);
		welcome5 = inflater.inflate(R.layout.welcome_5, null);
	
		dragableSpace.addView(welcome1);
		dragableSpace.addView(welcome2);
		dragableSpace.addView(welcome3);
		dragableSpace.addView(welcome4);
		dragableSpace.addView(welcome5);

		layout = new RelativeLayout(this);
		layout.addView(dragableSpace);

		circle = new DragableCircle(this);
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		params.setMargins(0, 0, 0, 10);
		layout.addView(circle, params);
		circle.SetCircleCount(dragableSpace.getChildCount());
		setContentView(layout);
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
//		if (keyCode == KeyEvent.KEYCODE_BACK) {
//			Intent i = new Intent(this,LoginActivity.class); // 通过Intent打开最终真正的主界面Main这个Activity
//			this.startActivity(i); // 启动Main界面
//			this.finish();
//			return true;
//		}
		return false;
	}
	@Override
	void initHandler() {
		// TODO Auto-generated method stub
		
	}
	@Override
	void initView() {
		// TODO Auto-generated method stub
		
	}
	@Override
	void initOnClick() {
		// TODO Auto-generated method stub
		
	}
	@Override
	void getDataToResolve(JSONResp response) {
		// TODO Auto-generated method stub
		
	}
}
